import { http } from '@/utils/http'
import { ExpertiseParams } from '@/service/expertise/expertise'

export interface CollectionParams {
  rtype?: string
  inptr?: string
  tags?: string
  cstatus?: number
  cid?: number
  page?: number
  limit?: number
}

export interface CollectionCourseItem {
  resId: number
  resCover: string
  resName: string
  isCompele: number
  overTimeStrYYYYMMD: string
  lookNum: number
}

export interface CollectionKnowledgeItem {
  resId: number
  frontImg: string
  title: string
  publishtime: string
  endtime: string
  look_num: number
}

export interface CollectionCourseData {
  totalCount: number
  items: CollectionCourseItem[]
}

export interface CollectionKnowledgeData {
  totalCount: number
  items: CollectionKnowledgeItem[]
}

/* 收藏的课程 */
export function getCollectionList({
  rtype,
  inptr,
  tags,
  cstatus,
  cid,
  page = 1,
  limit = 10,
}: CollectionParams = {}): Promise<IResData<CollectionCourseData>> {
  return http.get<CollectionCourseData>('/api/MP/GetMyCollect', {
    rtype,
    inptr,
    tags,
    cstatus,
    cid,
    page,
    limit,
  })
}

/* 收藏的知识 */
export function getCollectionKnowledgeList(
  page: number,
  limit: number,
): Promise<IResData<CollectionKnowledgeData>> {
  return http.get<CollectionKnowledgeData>('/api/MP/GetMyCollectExpertise', { page, limit })
}

export interface CollectResourceParams {
  resId: number
  resType: number
}

/* 收藏资源 */
export const collectResource = (resId: number, resType: number): Promise<IResData<void>> => {
  return http.post<void>('/api/MP/CollectResource', {
    resId,
    resType, // 0：课程；6：知识；2：微课；3：专题；4：活动
  })
}
